/*
 * Speedo.c
 *
 * Created: 4/1/2013 4:50:07 PM
 *  Author: Administrator
 */ 


#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>

#include "system.h"			// system wide definitions
#include "pins.h"			//pin definitions
#include "SystemTimer.h"	//system timer features
#include "LCD.h"
#include <stdio.h>

int main(void)
{
	// Set the clock prescaler to 0 (full speed ahead!)
	CLKPR =0;
		
	//----------------------------------------------------
	// Set up the system timer to fire at regular intervals
	// and provide a global timing reference
	//----------------------------------------------------
	 InitializeSystemTimer();

	 //PinChangeInit();

	// Initialize the LCD I/O pins
	 Initialize_LCD_IO();
	buttons_init();

	//----------------------------------------------------------------
	// Set - up the General Purpose I/O pins
	//----------------------------------------------------------------
	CLEAR_BIT(STATUS_LED_PORT,STATUS_LED);// 	; output  = 0
	SET_BIT(STATUS_LED_DDR, STATUS_LED);	// 	; output pin

	CLEAR_BIT(RPMCOUNTER_DDR, RPMCOUNTER); //Set as input pin


	//-----------------------------------------------------
	// Global Interrupt Enable
	//	a.k.a.  Point of no return!
	//-----------------------------------------------------
	sei();
		

	//----------------------------------------------------
	// Initialize the LCD (note: this depends on the system
	// timer initialization above)
	//----------------------------------------------------
	Initialize_LCD();


	
	
	char buffer[50];
	
    while(1)
    {
		if (has_second_elapsed())
		{
			LCD_SetPosition(0,0);
			snprintf(buffer,sizeof(buffer)-1,"%dm %ds     ", 
								timer_get_minutes(),
								timer_get_seconds());
			LCD_WriteString(buffer,sizeof(buffer)-1);
			
			
		}
		
		button_update();
		
		
		
        //TODO:: Please write your application code 
    }
}